borrow-or-share
Traits for either borrowing or sharing data.
See below for a basic usage of the crate. See the documentation for a detailed walkthrough.
Basic usage
Suppose that you have a generic type that either owns some data or holds a reference to them.
You can use this crate to implement on this type a method taking &self
that either borrows from *self
or from behind a reference it holds:
use BorrowOrShare;
;
// The returned reference is borrowed from `*text`
// and lives as long as `text`.
// The returned reference is borrowed from `*text.0`, lives
// longer than `text` and is said to be shared with `*text`.
Credit
Credit goes to @beepster4096 for figuring out a safe version of the code.